var fDisIds = $("#fDisIds").val();
var fDisnames = $("#fDisnames").val();
/*
 * @Description: 预加载
 * @param : 
 */
$(function (){
	var data = {};
	data.fDisIds = fDisIds;
	console.log(fDisnames);
//	console.log(data)
	$.ajax({
		url:pathUrl("dispatch/printCardBatch.action"),
		type:'POST',
		dataType:'JSON',
		async : false,
		data:data,
		success:function(data){
			console.log(data);
			$.each(data.rows,function(key,value){
				console.log(value.fOper);
				if(value.fOper=='油漆'||value.fOper=='包装'){
					var html = youprintPages(value);
					$("#print").append(html);
					$("#qrcode"+toString(value.fCode)).qrcode({
						width: 110,
						height: 110,
						correctLevel : 3,
						text: toUtf8(toString(value.fCode))
					});
					var canvas=document.getElementsByTagName("canvas")[0];
					var dataURL = canvas.toDataURL("image/png");
					var img = '<img src="'+dataURL+'"></img>';
					$("#qrcode"+toString(value.fCode)).html(img);
				}else{
					var html = printPages(value);
					$("#print").append(html);
					$("#qrcode"+toString(value.fCode)).qrcode({
						width: 110,
						height: 110,
						correctLevel : 3,
						text: toUtf8(toString(value.fCode))
					});
					var canvas=document.getElementsByTagName("canvas")[0];
					var dataURL = canvas.toDataURL("image/png");
					var img = '<img src="'+dataURL+'"></img>';
					$("#qrcode"+toString(value.fCode)).html(img);
				}
				
			});
			
		}
	});
	setTimeout(function(){
		print();
	}, 500);
});

/*
 * @Description: 打印
 * @param :
 */
function print() {
	$(".row").print({
		deferred: $.Deferred().done(function() { 
			window.close(); 
		})//打印完后自动关闭打印页面
	});
}

/*document.onreadystatechange = function () { 
	if(document.readyState == "complete"){ //当页面加载状态为完全结束时进入 
		print();//当页面加载完成后将loading页隐藏
	} 
}*/